/**
 * 
 */
package com.wistech.commons.serializer;

import java.nio.ByteBuffer;
import java.sql.Timestamp;
import static com.esotericsoftware.minlog.Log.*;

import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.serialize.LongSerializer;

/**
 * @author Liuye
 * 
 */
public class TimestampSerializer extends Serializer {

	@SuppressWarnings("unchecked")
	public Timestamp readObjectData(ByteBuffer buffer, Class type) {
		Timestamp timestamp = new Timestamp(LongSerializer.get(buffer, true));
		if (TRACE)
			trace("kryo", "Read timestamp: " + timestamp);
		return timestamp;
	}

	public void writeObjectData(ByteBuffer buffer, Object object) {
		LongSerializer.put(buffer, ((Timestamp) object).getTime(), true);
		if (TRACE)
			trace("kryo", "Wrote timestamp: " + object);
	}
}
